'''
Created on Dec 4, 2012

@author: gcoghlan, oxana
'''
import unittest
import validPieceMoves
from ChessBoard import ChessBoard
from ChessConsts import ChessConsts



class GetValidPawnMovesTest(unittest.TestCase):
    """Tests for the getValidPawnMoves function"""


    def setUp(self):
        self.cb = ChessBoard()


    def tearDown(self):
        pass


    def testGetValidPawnMovesForSimpleMove(self):
        
        fromPos = (0,1)
        validPawnMoves = validPieceMoves.getValidPawnMoves(self.cb, fromPos)
        (moves,specialMoves) = validPawnMoves
        self.assertEqual([(1, 0)], moves)
        self.assertEqual(0, len(specialMoves))
    
    
    def testGetValidPawnMovesForWhiteTurn(self):
        
        self.assertEqual(ChessConsts.WHITE, self.cb._turn)
        
        fromPos = (3,3)
        validPawnMoves = validPieceMoves.getValidPawnMoves(self.cb, fromPos)
        (moves,specialMoves) = validPawnMoves
        self.assertEqual([(3, 2)], moves)
        self.assertEqual(0, len(specialMoves))
        
    def testGetValidPawnMovesForAllWhiteStartTurns(self):
        
        self.assertEqual(ChessConsts.WHITE, self.cb._turn)
        
        for fx in range(8):
            fromPos = (fx,6)
            validPawnMoves = validPieceMoves.getValidPawnMoves(self.cb, fromPos)
            (moves,specialMoves) = validPawnMoves
            self.assertEqual([(fx,5), (fx,4)], moves)
            self.assertEqual({(fx,4): 1 }, specialMoves)
    
    
    def testGetValidPawnMovesForBlackTurn(self):
        
        self.cb._turn = ChessConsts.BLACK
        
        fromPos = (3,3)
        validPawnMoves = validPieceMoves.getValidPawnMoves(self.cb, fromPos)
        (moves,specialMoves) = validPawnMoves
        self.assertEqual([(3, 4)], moves)
        self.assertEqual(0, len(specialMoves))
      
    def testGetValidPawnMovesForAllBlackStartTurns(self):
        
        self.cb._turn = ChessConsts.BLACK
        
        for fx in range(8):
            fromPos = (fx,1)
            validPawnMoves = validPieceMoves.getValidPawnMoves(self.cb, fromPos)
            (moves,specialMoves) = validPawnMoves
            self.assertEqual([(fx,2), (fx,3)], moves)
            self.assertEqual({(fx,3): 1 }, specialMoves)
    
    def testGetValidPawnMovesWhenBlocked(self):
        
        self.assertEqual(ChessConsts.WHITE, self.cb._turn)
        # self.cb._board[2][3] = 'P'
        self.cb.SetFigure(3, 2, 'P')
        self.assertFalse(self.cb.isFree(3, 2))
        
        fromPos = (3,3)
        validPawnMoves = validPieceMoves.getValidPawnMoves(self.cb, fromPos)
        (moves,specialMoves) = validPawnMoves
        self.assertEqual([], moves)
        self.assertEqual({}, specialMoves)

    def testEPMoves(self):

        self.cb._turn = ChessConsts.BLACK

        self.cb.SetFigure(0, 4, 'P')
        self.cb.SetFigure(1, 4, 'p')

        self.cb._ep = [0,4]
        validPawnMoves = validPieceMoves.getValidPawnMoves(self.cb, (1,4))
        (moves,specialMoves) = validPawnMoves
        self.assertEqual([(1, 5), (0, 5)], moves)
        self.assertEqual({(0, 5): 2}, specialMoves)
    

if __name__ == "__main__":
    #import sys;sys.argv = ['', 'Test.testName']
    unittest.main()